<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
pre_forum_forumfield 版块扩展表

fid, mediumint, 版块id,
description, text, 解释说明,
password, varchar, 私密论坛密码,
icon, varchar, 图标,
redirect, varchar, URL转发,
attachextensions, varchar, 允许上传附件类型,
creditspolicy, mediumtext, 版块积分策略,
formulaperm, text, 版块权限表达式,
moderators, text, 版主列表，格式:admin,
rules, text, 版块规则,
threadtypes, text, 主题分类，序列化存放的设置，格式为一个数组,
threadsorts, text, 分类信息，序列化存放的设置，格式为一个数组,
viewperm, text, 阅读权限, 格式:	1	4	5,
postperm, text, 发表权限, 格式:	1	4	5,
replyperm, text, 回复权限, 格式:	1	4	5,
getattachperm, text, 下载附件权限, 格式:	1	4	5,
postattachperm, text, 上传附件权限, 格式:	1	4	5,
postimageperm, text, 上传图片权限, 格式:	1	4	5,
spviewperm, text, 不受限于版权权限表达式, 格式:	1	4	5,
seotitle, text, 版块seo标题,
keywords, text, 版块seo关键词,
seodescription, text, 版块seo描述,
supe_pushsetting, text, supe推送设置，序列化存放设置数据，格式为一个数组。,
modrecommend, text, 版主推荐规则,
threadplugin, text, 特殊主题插件数据,
replybg, text, 回复框背景,
extra, TEXT,
jointype, tinyint, 加入群组方式 -1为关闭，0为公开， 2邀请,
gviewperm, tinyint, 群组浏览权限 0:仅成员 1:所有用户,
membernum, smallint, 群组成员数,
dateline, int, 群组创建时间,
lastupdate, int, 群组最后更新时间,
activity, int, 群组活跃度,
founderuid, mediumint, 群组创始人UID,
foundername, varchar, 群组创始人名称,
banner, varchar, 群组头图片,
groupnum, smallint, 分类下的群组数量,
commentitem, TEXT,
relatedgroup, TEXT,
picstyle, tinyint, 帖子列表是否以图片形式显示 0:否 1:是,
widthauto, tinyint, 默认是否宽屏 0:全局 -1:宽屏 1:窄屏,
noantitheft, tinyint, 禁止防采集,
noforumhidewater, tinyint, 禁止隐藏水帖,
noforumrecommend, tinyint, 禁止推荐回复,
livetid, mediumint, 版块直播帖tid,
price, mediumint, 进入版块所需支付的积分,

 *      $Id: table_forum_forumfield.php 32916 2013-03-22 08:51:36Z zhangjie $
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class table_forum_forumfield extends discuz_table
{
	public function __construct() {

		$this->_table = 'forum_forumfield';
		$this->_pk    = 'fid';

		parent::__construct();
	}
	public function fetch_all_by_fid($fids) {
		$fids = array_map('intval', (array)$fids);
		if(!empty($fids)) {
			return DB::fetch_all("SELECT * FROM %t WHERE fid IN(%n)", array($this->_table, $fids), $this->_pk);
		} else {
			return array();
		}
	}
	public function fetch_all_field_perm() {
		return DB::fetch_all("SELECT fid, viewperm, postperm, replyperm, getattachperm, postattachperm, postimageperm FROM ".DB::table($this->_table)." WHERE founderuid=0");
	}
	public function fetch_groupnum_by_founderuid($uid) {
		if(empty($uid)) {
			return false;
		}
		return DB::result_first("SELECT COUNT(*) FROM ".DB::table($this->_table)." WHERE founderuid=%d", array($uid));
	}
	public function update_groupnum($fid, $num) {
		if(!intval($fid) || !intval($num)) {
			return false;
		}
		DB::query("UPDATE %t SET ".DB::field('groupnum', $num, '+')." WHERE fid=%d", array('forum_forumfield', $fid));
	}
	public function update_membernum($fid, $num = 1) {
		if(!intval($fid) || !intval($num)) {
			return false;
		}
		DB::query("UPDATE %t SET ".DB::field('membernum', $num, '+')." WHERE fid=%d", array('forum_forumfield', $fid));
	}
	public function fetch_info_for_attach($fid, $uid) {
		return DB::fetch_first("SELECT f.fid, f.viewperm, f.getattachperm, a.allowgetattach, a.allowgetimage FROM %t f LEFT JOIN %t a ON a.uid=%d AND a.fid=f.fid WHERE f.fid=%d",
            array('forum_forumfield', 'forum_access', $uid, $fid));
	}
	public function check_moderator_for_uid($fid, $uid, $accessmasks = 0) {
		if(!intval($fid) || !intval($uid)) {
			return false;
		}
		if($accessmasks) {
			$accessadd1 = ', a.allowview, a.allowpost, a.allowreply, a.allowgetattach, a.allowgetimage, a.allowpostattach';
			$accessadd2 = "LEFT JOIN ".DB::table('forum_access')." a ON a.".DB::field('uid', $uid)." AND a.".DB::field('fid', $fid);
		}
		return DB::fetch_first("SELECT ff.postperm, m.uid AS istargetmod $accessadd1
				FROM ".DB::table($this->_table)." ff
				$accessadd2
				LEFT JOIN ".DB::table('forum_moderator')." m ON m.fid=%d AND m.uid=%d
				WHERE ff.fid=%d", array($fid, $uid, $fid));
	}
}

?>